package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.Teacher;
import com.atguigu.eduservice.mapper.TeacherMapper;
import com.atguigu.eduservice.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-06-18
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {


    @Override
    public Map<String, Object> getTeacherFrontList(Page<Teacher> pageTeahcer) {
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        //把分页数据封装到pageTeacher对象
        baseMapper.selectPage(pageTeahcer,wrapper);

        List<Teacher> records = pageTeahcer.getRecords();
        long current = pageTeahcer.getCurrent();
        long pages = pageTeahcer.getPages();
        long size = pageTeahcer.getSize();
        long total = pageTeahcer.getTotal();
        boolean hasNext = pageTeahcer.hasNext();//下一页
        boolean hasPrevious = pageTeahcer.hasPrevious();//上一页

        //把分页数据取出，放到map集合中
        Map<String,Object> map = new HashMap<>();
        map.put("items",records);
        map.put("current",current);
        map.put("pages",pages);
        map.put("size",size);
        map.put("total",total);
        map.put("hasNext",hasNext);
        map.put("hasPrevious",hasPrevious);

        return map;
    }
}
